<template>
	<view>
		<custom-navigation-bar title="添加商品"></custom-navigation-bar>
		<view class="main">
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						商品名称
					</view>
					<view class="form-item-countent">
						<input type="text" class="form-item-input" placeholder="请输入商品名称" v-model="goods.goods.name" />
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						套餐类型
					</view>
					<view class="form-item-countent">
						<picker model='selector' @change="cateTypeChange" :range="cateTypeArr" range-key="name">
							<input type="text" class="picker" :value="cateType" placeholder="请选择套餐类型" disabled/>
						</picker>
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						库存
					</view>
					<view class="form-item-countent">
						<input type="text" class="form-item-input" placeholder="请输入库存" v-model="goods.goods.stockNum" />
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						类型
					</view>
					<view class="form-item-countent">
						<picker model='selector' @change="typeChange" :range="typeArr" range-key="name">
							<input type="text" class="picker" :value="type" placeholder="请选择类型"  disabled/>
						</picker>
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						商品分类
					</view>
					<view class="form-item-countent">
						<picker model='selector' @change="menuChange" :range="menuArr" range-key="name">
							<input type="text" class="picker" :value="menu" placeholder="请选择商品分类" disabled/>
						</picker>
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						售价
					</view>
					<view class="form-item-countent">
						<input type="digit" maxlength="10" class="form-item-input" placeholder="请输入售价" v-model="goods.goods.price" />
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						原价
					</view>
					<view class="form-item-countent">
						<input type="digit" class="form-item-input" placeholder="请输入原价" v-model="goods.goods.originPrice" />
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						分佣比例
					</view>
					<view class="form-item-countent">
						<input type="digit" maxlength="5" class="form-item-input" placeholder="请输入分佣比例最大100%" v-model="goods.goods.dispense"/>%
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
		
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						有效期
					</view>
					<view class="form-item-countent">
						<picker mode='date' @change="endTimeChange">
							<input type="text" class="picker"  placeholder="请选择有效期(不选为长期有效)" v-model="goods.goods.endTime" disabled/>
						</picker>
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						重复购买 
					</view>
					<view class="form-item-countent"> 
						<picker model='selector' @change="isRepeatChange" :range="isRepeatArr" range-key="name">
							<input type="text" class="picker" :value="isRepeat" placeholder="请选择是否允许重复购买" disabled/>
						</picker> 
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>

			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						限购数量
					</view>
					<view class="form-item-countent">
						<input type="number" class="form-item-input" placeholder="请输入限购数量" v-model="goods.goods.limitNum" />
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>

			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						营业时间
					</view>
					<view class="form-item-countent">
						<input type="text" class="form-item-input" placeholder="请输入消费时间"  v-model="goods.goods.useTime" />
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>

			<view class="form-item">
				<view class="form-item-1">
					<view class="form-item-lable">
						是否预约
					</view>
					<view class="form-item-countent">
						<picker model='selector' @change="isBookChange" :range="isBookArr" range-key="name">
							<input type="text" class="picker" :value="isBook" placeholder="请选择是否需要预约" disabled/>
						</picker> 
					</view>
					<view class="form-item-right">
						<image src="/static/gengduo@3x(1).png" class="form-item-image"></image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view style="width: 84%;float: left;margin-left: 8%;">
			  		<uni-file-picker @select="thumbnailSelect" @delete="thumbnailDelete" limit="1" title="商品缩略图" v-model="thumbnailArr"></uni-file-picker> 
					<view class="ta_01"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="upload_01">
			  		<uni-file-picker @select="mainImageSelect" @delete="mainImageDelete" limit="5" title="商品主图" v-model="mainImageArr" ></uni-file-picker>
					<view class="ta_01"></view>
				</view>
			</view>
			<view class="form-item" >
				<view class="upload_01" >
					<view class="a_title" style="width: 100%;">
						邻里团购
					</view>
					<view v-for="(item,index) in commodityDetail" :key="index">
						<view class="b_content" style="width: 100%;">
							<input disabled placeholder="请输入主标题" :value="item.title" class="c_ttt" @focus="setCommodityDetailIndex(index)" @input="commodityDetailTitleInput" />
							<view v-for="(item1,index1) in item.detail" :key="index1">
								 <view class="b-1-2">
									 <input v-if="index==0" disabled placeholder="请输入标签" :value="item1.title" class="d_ttt" @focus="setCommodityDetailContentIndex(index,index1)" @input="commodityDetailContentTitleInput"/>
									 <input v-if="index>0" placeholder="请输入标签" :value="item1.title" class="d_ttt" @focus="setCommodityDetailContentIndex(index,index1)" @input="commodityDetailContentTitleInput"/>
									 <input placeholder="请输入内容" :value="item1.content" class="g_ttt" @focus="setCommodityDetailContentIndex(index,index1)" @input="commodityDetailContentContentInput"/> 
									 <image v-if="index1==0&&index>0"  src="/static/add.png" class="form-item-image-1" @click="addCommodityDetailContent(index)"></image> 
									 
									 <image v-if="index1 > 0 && index1==item.detail.length-1 &&index>0" src="/static/sub.png" class="form-item-image-1" @click="subCommodityDetailContent(index,index1)"></image>
								 </view>
								  <view style="width: 100%;float: left;height: 5rpx;"></view>
							</view> 
						</view>
						<!-- <view class="b-1-1">
							<image v-if="index==0"  src="/static/add.png" class="form-item-image-1" @click="addCommodityDetail()"></image>
							<image v-if="index > 0 && index==commodityDetail.length-1" src="/static/sub.png" class="form-item-image-1" @click="subCommodityDetail(index)"></image>
						</view> -->
					</view> 
					<view class="ta_02" style="height: 20rpx;"></view>
				</view>
			</view> 
			<view class="form-item">
				<view class="form-item-textarea">
					<view class="form-item-lable">
						品牌简介
					</view>
					<view class="form-item-countent" >
						<textarea v-model="goods.goodsDetail.concise" class="form-item-textarea-textarea" placeholder="请输入品牌简介(选填,300字内)" maxlength="300"></textarea>
					</view>
				</view>
			</view>
			
			<view class="form-item">
				<view class="form-item-textarea">
					<view class="form-item-lable">
						服务优势
					</view>
					<view class="form-item-countent" >
						<textarea v-model="goods.goodsDetail.advantage" class="form-item-textarea-textarea" placeholder="请输入服务优势(选填,300字内)"  maxlength="300"></textarea>
					</view>
				</view>
			</view>
			
			<view class="form-item">
				<view class="form-item-textarea">
					<view class="form-item-lable">
						宣传文案
					</view>
					<view class="form-item-countent" >
						<textarea v-model="goods.goodsDetail.sellInfo" class="form-item-textarea-textarea" placeholder="请输入宣传文案(300字内)"  maxlength="300"></textarea>
					</view>
				</view>
			</view>
			
			<view class="form-item">
				<view class="upload_01">
			  		<uni-file-picker @select="detailImgSelect" @delete="detailImgDelete" v-model="detailImgArr" limit="9" title="图文详情" ></uni-file-picker>
					<view class="ta_01"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="upload_01" >
					<view class="a_title" style="width: 100%;">
						购买须知
					</view>
					<view v-for="(item,index) in buyNotice" :key="index">
						<view class="b_content" style="width: 100%;">
							<input placeholder="请输入主标题" :value="item.title" class="c_ttt" @focus="setBuyNoticeIndex(index)" @input="buyNoticeTitleInput" disabled/>
							<view v-for="(item1,index1) in item.detail" :key="index1">
								<view class="b-1-2" >
									<input :value="item1.content" placeholder="请输入内容" class="z_ttt" @focus="setBuyNoticeDetailIndex(index,index1)" @input="buyNoticeContentInput" />
									
									<image v-if="index1==0"  src="/static/add.png" class="form-item-image-1" @click="addBuyNoticeContent(index)"></image>
									<image v-if="index1 > 0 && index1==item.detail.length-1" src="/static/sub.png" class="form-item-image-1" @click="subBuyNoticeContent(index,index1)"></image> 
								
								</view> 
							</view>
							 <view style="width: 100%;height: 10rpx;float: left;"></view>
						</view>
						<!-- <view class="b-1-1">
							<image v-if="index==0"  src="/static/add.png" class="form-item-image-1" @click="addBuyNotice()" ></image>
							<image v-if="index>0 && index==buyNotice.length-1" src="/static/sub.png" class="form-item-image-1" @click="subBuyNotice(index)" ></image>
						</view> -->
					</view> 
				</view>
			</view>
		</view>
		<view class="form-item">
			<view style="width: 84%;float: left;margin-left: 8%;margin-top: 20px;">
				<view class="btn" @click="submit">提交</view>
			</view>
		</view>
		<view class="btn-0010"></view>
	</view>
</template>

<script setup>
	import {
		defineComponent, ref
	} from 'vue';
	import CustomNavigationBar from '@/components/CustomNavigationBar.vue';
	import http from '../../../utils/http';
	import {
		generateApplicationId,
		getCurrentTimestamp,
		generateTime
	} from '../../../utils/timeUtils';
	var id=ref();	
	import {
		onLoad,
		onPageScroll
	} from '@dcloudio/uni-app';
	const thumbnailArr=ref([]);
	const mainImageArr=ref([]);
	const detailImgArr=ref([]);
	
	
	function liShi(){
		wx.getStorage({
		  key: 'key',
		  success (responseData) {
		    console.log("1111111111111",responseData.data);
			responseData.data.userId=getApp().globalData.shopUserId;
			
			goods.value.goods=responseData.data.goods;
			goods.value.goodsDetail=responseData.data.goodsDetail;
			menu.value=responseData.data.goods.menuName;
			//套餐类型回显
			for(var i=0;i<cateTypeArr.value.length;i++){
				if(goods.value.goods.cateType==cateTypeArr.value[i].id){
					cateType.value=cateTypeArr.value[i].name;
				} 
			}
			//类型回显
			for(var i=0;i<typeArr.value.length;i++){
				if(goods.value.goods.type==typeArr.value[i].id){
					type.value=typeArr.value[i].name;
				} 
			}
			//是否
			for(var i=0;i<isRepeatArr.value.length;i++){
				if(goods.value.goods.isRepeat==isRepeatArr.value[i].id){
					isRepeat.value=isRepeatArr.value[i].name;
				} 
			}
			for(var i=0;i<isBookArr.value.length;i++){
				if(goods.value.goods.isBook==isBookArr.value[i].id){
					isBook.value=isBookArr.value[i].name;
				} 
			}
			//商品缩略图
			thumbnailArr.value=[{
				url:goods.value.goods.thumbnail
			}]; 
			//图文详情
			commodityDetail.value=goods.value.goodsDetail.deailInfo;
			 
			//商品主图
			const mainImage=[];
			for(var i=0;i<goods.value.goodsDetail.mainImage.length;i++){
				mainImage.push({
					url:goods.value.goodsDetail.mainImage[i]
				})
			} 
			mainImageArr.value=mainImage;
			buyNotice.value=goods.value.goodsDetail.buyNotice;
			//图文性情
			const detailImg=[];
			
			for(var i=0;i<goods.value.goodsDetail.detailImg.length;i++){
				detailImg.push({
					url:goods.value.goodsDetail.detailImg[i]
				})
			} 
			detailImgArr.value=detailImg;
			
		  }
		})
	}
	
	
	onLoad((query) => {
		id.value=query.id;
		console.log(id.value);
		
		if(!query.id){
			
			uni.showModal({
			    title: '是否重载编辑历史', 
			    success: function (res) {
			        if (res.confirm) {
			            liShi();
						
						setInterval(() => { 
							const data=goods.value;
							data.goodsDetail.deailInfo=commodityDetail.value;
							data.goodsDetail.buyNotice=buyNotice.value; 
							  
							wx.setStorage({
							  key:"key",
							  data:data
							});
							console.log("11111",data)
						},3000);
						
			        } else if (res.cancel) {
			            setInterval(() => { 
			            	const data=goods.value;
			            	data.goodsDetail.deailInfo=commodityDetail.value;
			            	data.goodsDetail.buyNotice=buyNotice.value; 
			            	  
			            	wx.setStorage({
			            	  key:"key",
			            	  data:data
			            	});
			            	console.log("11111",data)
			            },3000);
			        }
			    }
			});
			
			
			
			return;
		}
		uni.showLoading({
			title: '数据加载中',
			mask:true
		}); 
		
		http.request({
		 	url: "/shop/goods/get",
		 	method: "POST",
		 	data: {
		 		"id":query.id,
		 	}
		}).then((responseData) => { 
			uni.hideLoading(); 
			if(responseData.code==1){
				responseData.data.goodsDetail.buyNotice=JSON.parse(responseData.data.goodsDetail.buyNotice);
				responseData.data.goodsDetail.deailInfo=JSON.parse(responseData.data.goodsDetail.deailInfo);
				responseData.data.goodsDetail.detailImg=JSON.parse(responseData.data.goodsDetail.detailImg);
				responseData.data.goodsDetail.mainImage=JSON.parse(responseData.data.goodsDetail.mainImage);
				
				goods.value.goods=responseData.data.goods;
				goods.value.goodsDetail=responseData.data.goodsDetail;
				menu.value=responseData.data.goods.menuName;
				//套餐类型回显
				for(var i=0;i<cateTypeArr.value.length;i++){
					if(goods.value.goods.cateType==cateTypeArr.value[i].id){
						cateType.value=cateTypeArr.value[i].name;
					} 
				}
				//类型回显
				for(var i=0;i<typeArr.value.length;i++){
					if(goods.value.goods.type==typeArr.value[i].id){
						type.value=typeArr.value[i].name;
					} 
				}
				//是否
				for(var i=0;i<isRepeatArr.value.length;i++){
					if(goods.value.goods.isRepeat==isRepeatArr.value[i].id){
						isRepeat.value=isRepeatArr.value[i].name;
					} 
				}
				for(var i=0;i<isBookArr.value.length;i++){
					if(goods.value.goods.isBook==isBookArr.value[i].id){
						isBook.value=isBookArr.value[i].name;
					} 
				}
				//商品缩略图
				thumbnailArr.value=[{
					url:goods.value.goods.thumbnail
				}]; 
				//图文详情
				commodityDetail.value=goods.value.goodsDetail.deailInfo;
				 
				//商品主图
				const mainImage=[];
				for(var i=0;i<goods.value.goodsDetail.mainImage.length;i++){
					mainImage.push({
						url:goods.value.goodsDetail.mainImage[i]
					})
				} 
				mainImageArr.value=mainImage;
				buyNotice.value=goods.value.goodsDetail.buyNotice;
				//图文性情
				const detailImg=[];
				
				for(var i=0;i<goods.value.goodsDetail.detailImg.length;i++){
					detailImg.push({
						url:goods.value.goodsDetail.detailImg[i]
					})
				} 
				detailImgArr.value=detailImg;
				
				
			}else{
				uni.showToast({
					icon: 'error',
					title: '数据异常'
				})
			}
		}).catch((err) => {
			uni.hideLoading();
		 	uni.showToast({
		 		icon: 'error',
		 		title: '请求失败'
		 	})
		})
	})
	
	const goods = ref({
		userId:getApp().globalData.shopUserId,
		goods:{
			name: "",
			type: "",
			menuId: "",
			price: '',
			originPrice: '',
			dispense:"",
			cateType: "",
			beginTime: "",
			endTime: '',
			isRepeat: '',
			limitNum: '',
			useTime: "",
			stockNum:'',
			thumbnail:'',
			isBook:''
		},
		goodsDetail:{
			mainImage:[],
			deailInfo:[],
			detailImg:[],
			buyNotice:[],
			advantage:"",
			concise:"",
			sellInfo:''
		}  
	});
	 
	function upload(tempFilePaths,type){
		uni.showLoading({
			title: '图片上传中',
			mask:true
		});
		var width='';
		var height='';
		if(type=='thumbnail'){
			width=400;
			height=400
		}
		uni.uploadFile({
			url: getApp().globalData.upLoadUrl,
			filePath: tempFilePaths.path,
			name: 'file', // 文件字段名
			formData: {
				"fileType": "application",
				"fileName": getCurrentTimestamp(),
				"userId": goods.value.userId,
				width:width,
				height:height
			},
			success: (uploadRes) => { 
				uni.hideLoading();
				console.log(uploadRes.data);
				let jsonData = JSON.parse(uploadRes.data);
				if(jsonData.code==1){
					if(type=='thumbnail'){
						goods.value.goods.thumbnail=jsonData.data;
					}else if(type=='mainImage'){
						goods.value.goodsDetail.mainImage.push(jsonData.data);
					}else{ 
						goods.value.goodsDetail.detailImg.push(jsonData.data);
					}
				}else{
					uni.showToast({
						title: '图片上传失败',
					    icon:'error',
						duration: 2000, //提示的延迟时间，单位毫秒，默认：1500
					    mask:true
					});
				}
			},
			fail: (error) => {
				uni.hideLoading();
				uni.showToast({
					title: '图片上传失败',
				    icon:'error',
					duration: 2000, //提示的延迟时间，单位毫秒，默认：1500
				    mask:true
				});
			}
		});
	}
	function thumbnailSelect(e) {
		console.log("22222222",e)
		const tempFilePaths = e.tempFiles;
		upload(tempFilePaths[0],'thumbnail');
		
	} 
	function thumbnailDelete(e) {
		goods.value.goods.thumbnail='';
	} 
	function mainImageSelect(e) {
		console.log("22222222",e)
		const tempFilePaths = e.tempFiles;
		for(var i=0;i<tempFilePaths.length;i++){
			upload(tempFilePaths[i],'mainImage');
		} 
	} 
	function mainImageDelete(e) {
		console.log(e.index);
		goods.value.goodsDetail.mainImage.splice(e.index, 1); 
	}
	
	function detailImgSelect(e) {
		console.log("22222222",e)
		const tempFilePaths = e.tempFiles;
		for(var i=0;i<tempFilePaths.length;i++){
			upload(tempFilePaths[i],'detailImg');
		} 
	} 
	function detailImgDelete(e) {
		console.log(e.index);
		goods.value.goodsDetail.detailImg.splice(e.index, 1); 
	}
	
	function submitM(type){
		uni.showLoading({
			title: '提交中',
			mask:true
		});
		//commodityDetail、buyNotice
		goods.value.goodsDetail.deailInfo=commodityDetail.value;
		goods.value.goodsDetail.buyNotice= buyNotice.value; 
		console.log(goods.value);
		
		http.request({
			url: "/shop/goods/add",
			method: "POST",
			data: {
				"userId": goods.value.userId,
				goods:goods.value.goods,
				goodsDetail:{
					mainImage:JSON.stringify(goods.value.goodsDetail.mainImage),
					deailInfo:JSON.stringify(goods.value.goodsDetail.deailInfo),
					detailImg:JSON.stringify(goods.value.goodsDetail.detailImg),
					buyNotice:JSON.stringify(goods.value.goodsDetail.buyNotice),
					concise:goods.value.goodsDetail.concise,
					advantage:goods.value.goodsDetail.advantage,
					sellInfo:goods.value.goodsDetail.sellInfo
				}
			}
		}).then((res) => { 
			console.log(res);
			uni.hideLoading();
			 if(res.code==1){
				if(type==1){
					uni.showToast({
						title: '添加成功'
					})
				}else{
					uni.showToast({
						title: '修改成功'
					})
				}
				 
				 setTimeout(function () { 
					const pages = getCurrentPages();
					const beforePage = pages[pages.length - 2];
					console.log(beforePage)
					if(beforePage){
						beforePage.$vm.$.exposed.getGoods() 
						uni.navigateBack(); 
					}
				 }, 2000);
				 
			 }else if(res.code==0){
				 uni.showToast({
				 	icon: 'error',
				 	title: res.message
				 })
			 }else if(res.code==-1){
				uni.navigateTo({
					url: "/pages/login/login"
				});
			 }
		}).catch((err) => {
			uni.showToast({
				icon: 'error',
				title: '请求失败'
			})
		})
	}
	 
	function submit(){
		
		if(goods.value.goods.id){
			uni.showModal({
			    title: '提示',
			    content: '提交将重新进入审核，是否提交。',
			    success: (res) => {
			        submitM(2);
			    }
			});
		}else{
			submitM(1)
		}
		 
		
	} 
	const typeArr = ref([{
		id: 1,
		name: '服务产品'
	}]);
	//类型
	const type = ref('');
	const typeIndex = ref(0);

	function typeChange(e) {
		const index = e.detail.value;
		type.value = typeArr.value[index].name;
		typeIndex.value = typeArr.value[index].id;
		goods.value.goods.type=typeArr.value[index].id;
	} 
	
	const cateTypeArr = ref([{
			id: 1,
			name: '体验套餐'
		},
		{
			id: 2,
			name: '正价套餐'
		},
		{
			id: 3,
			name: '抵扣券'
		}
	]);
	
	
	
	//类型
	const cateType = ref('');
	const cateTypeIndex = ref(0);
	
	function cateTypeChange(e) {
		const index = e.detail.value;
		cateType.value = cateTypeArr.value[index].name;
		cateTypeIndex.value = cateTypeArr.value[index].id;
		goods.value.goods.cateType=cateTypeArr.value[index].id;
	} 
	
	const isBookArr=ref([
		{
			id:0,
			name:'不需要'
		},
		{
			id:1,
			name:'需要'
		}
	]);
	const isBook=ref("");
	const isBookIndex = ref(0);
	function isBookChange(e){
		const index = e.detail.value;
		isBook.value = isBookArr.value[index].name;
		isBookIndex.value = isBookArr.value[index].id;
		goods.value.goods.isBook=isBookArr.value[index].id;
	}
	
	const menuArr = ref();
	//类型
	const menu = ref('');
	const menuIndex = ref(0);
	function menuInt(){
		http.request({
			url: "/shop/goods/sys/menu",
			method: "POST",
			data: {
				"userId": goods.value.userId,
			}
		}).then((responseData) => { 
			 if(responseData.code==1){
				 menuArr.value=responseData.data;
				 console.log(menuArr.value)
			 }
		}).catch((err) => {
			uni.showToast({
				icon: 'error',
				title: '请求失败'
			})
		})
	}
	menuInt(); 
	function menuChange(e) {
		const index = e.detail.value;
		menu.value = menuArr.value[index].name;
		menuIndex.value = menuArr.value[index].id;
		goods.value.goods.menuId=menuArr.value[index].id;
	}
	
	function endTimeChange(e){
		goods.value.goods.endTime=e.detail.value;
	}
	
	
	const isRepeatArr = ref([{
		id: 1,
		name: '允许'
	},
	{
		id: 2,
		name: '不允许'
	}
	]);
	//类型
	const isRepeat = ref('');
	const isRepeatIndex = ref(0);
	
	function isRepeatChange(e) {
		const index = e.detail.value;
		isRepeat.value = isRepeatArr.value[index].name;
		isRepeatIndex.value = isRepeatArr.value[index].id;
		goods.value.goods.isRepeat=isRepeatArr.value[index].id;
		console.log(isRepeat.value)
	} 
	
	
//----------------------------------商品详情详情开始--------------------------
	 //详情输入框的索引
	 const commodityDetailIndex=ref(0);
	 //获取详情输入框的索引
	 function setCommodityDetailIndex(index){
	 	commodityDetailIndex.value=index;
	 }
	 const commodityDetail=ref([
	 	{
	 		title:'基本信息',
	 		detail:[
	 			{
	 				title:'服务名称：',
	 				content:''
	 			},
				{
					title:'服务类型：',
					content:''
				},
				{
					title:'交付形式：',
					content:''
				},
				{
					title:'交易保障：',
					content:''
				},
				{
					title:'价格优势：',
					content:''
				}
	 		]
	 	},
		{
			title:'产品详情',
			detail:[
				{
					title:'',
					content:''
				}
			]
		}
	 ]);
	 //添加一级标题内容
	 function addCommodityDetail (){
	 	commodityDetail.value.push({
	 		title:'',
	 		detail:[
	 			{
	 				title:'',
	 				content:''
	 			}
	 		]
	 	});
	 	console.log(commodityDetail.value);
	 }
	 //删除一级标题内容
	 function subCommodityDetail (index){
	 	commodityDetail.value.splice(index, 1);
	 }
	 //一级标题输入
	 function commodityDetailTitleInput(event){
	 	commodityDetail.value[commodityDetailIndex.value].title=event.target.value
	 }
	 //添加二级标题
	 function addCommodityDetailContent(index){
	 	commodityDetail.value[index].detail.push(
	 		{
	 			title:'',
	 			content:''
	 		}
	 	);
	 } 
	 //删除二级标题
	 function subCommodityDetailContent(index,index1){
	 	commodityDetail.value[index].detail.splice(index1, 1);
	 }
	 //二级标题索引
	 const commodityDetailContentIndex=ref([0,0]);
	 function setCommodityDetailContentIndex(index,index1){
	 	commodityDetailContentIndex.value=[index,index1];
	 }
	 //二级标题输入
	 function commodityDetailContentTitleInput(event){
	 	commodityDetail.value[commodityDetailContentIndex.value[0]].detail[commodityDetailContentIndex.value[1]].title=event.target.value;
	 }
	 //二级标题内容输入
	 function commodityDetailContentContentInput(event){
	 	commodityDetail.value[commodityDetailContentIndex.value[0]].detail[commodityDetailContentIndex.value[1]].content=event.target.value;
	 }
	 //----------------------------------商品详情结束--------------------------
	 
	 //----------------------------------购买须知开始--------------------------
	 //购买须知索引
	 const buyNoticeIndex=ref(0);
	 function setBuyNoticeIndex(index){
	 	buyNoticeIndex.value=index;
	 	console.log(buyNoticeIndex.value)
	 }
	 const buyNotice=ref([
	 	{
	 		title:'有效期',
	 		detail:[
	 			{
	 				content:''
	 			}
	 		]
	 	},
		{
			title:'预约信息',
			detail:[
				{
					content:''
				}
			]
		},
		{
			title:'适用人数',
			detail:[
				{
					content:''
				}
			]
		},
		{
			title:'规则提醒',
			detail:[
				{
					content:''
				}
			]
		},
		{
			title:'温馨提示',
			detail:[
				{
					content:''
				}
			]
		}
	 ]);
	 //添加一级标题
	 function addBuyNotice(){
	 	buyNotice.value.push(
	 		{
	 			title:'',
	 			detail:[
	 				{
	 					content:''
	 				}
	 			]
	 		}
	 	);
	 	console.log(buyNotice.value)
	 }
	 //删除一级标题
	 function subBuyNotice(index){
	 	buyNotice.value.splice(index, 1); 
	 }
	 //一级标题内容输入
	 function buyNoticeTitleInput(event){
	 	console.log(event.target.value+'-----'+buyNoticeIndex.value)
	 	buyNotice.value[buyNoticeIndex.value].title=event.target.value;  
	 }
	 //二级标题索引
	 const buyNoticeDetailIndex=ref([0,0]);
	 //设置二级标题索引
	 function setBuyNoticeDetailIndex(index,index1){
	 	buyNoticeDetailIndex.value=[index,index1];
	 }
	 //添加二级内容
	 function addBuyNoticeContent(index){
	 	buyNotice.value[index].detail.push({
	 		content:''
	 	});  
	 }
	 //删除二级内容
	 function subBuyNoticeContent(index,index1){
	 	buyNotice.value[index].detail.splice(index1, 1);
	 }
	 //二级内容输入
	 function buyNoticeContentInput(event){
	 	buyNotice.value[buyNoticeDetailIndex.value[0]].detail[buyNoticeDetailIndex.value[1]].content=event.target.value;
	 }
	 
</script>

<style>
	@import "../../application/form.scss";
</style>